import datetime

from django.shortcuts import get_object_or_404, redirect

from brispone.util.decorators import render_to
from brispone.util import inc_paginate
from brispone.models import Event

@render_to('brispone/event/list.html')
def list(request):
    events = Event.objects.active_events()
    return {'events':events}

@render_to('m/event/list.html')
def mlist(request):
    events = Event.objects.active_events()
    return {'events':events}

@render_to('brispone/event/inc_list.html')
def inc_list(request):
    get_page = request.GET['gp']
    events = Event.objects.all()
    objects = inc_paginate(events, get_page)
    return {'objects':objects}

@render_to('m/event/inc_list.html')
def minc_list(request):
    get_page = request.GET['gp']
    events = Event.objects.all()
    objects = inc_paginate(events, get_page)
    return {'objects':objects}

@render_to('brispone/event/detail.html')
def detail(request, event_id):
    event = get_object_or_404(Event, pk=event_id)
    return {'event':event}

@render_to('m/event/detail.html')
def mdetail(request, event_id):
    event = get_object_or_404(Event, pk=event_id)
    return {'event':event}

def check_active(request):
    aevents = Event.objects.filter(active=True)
    today = datetime.date.today()
    for aevent in aevents:
        if aevent.edate < today:
            aevent.active = False
            aevent.save()
    return redirect('/admin/brispone/event/')
    
    